//
//  SAShopPreviewVC.m
//  yidiantong
//
//  Created by 黄志刚 on 2020/10/9.
//

#import "SAShopPreviewVC.h"
#import "SAShopPreviewCell.h"
#import "SAEditShopVC.h"
#import "SAProductOverModel.h"
#import "SAProductListAPI.h"
#import "SAAddShopVC.h"
#import "SASupplierScreeningView3.h"
#import "SAShopBatchVC.h"
#import "YBImageBrowser.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "ScanHelper.h"
#import "SAProductGetConditionAPI.h"
#import "SAProductBatchIsDeleteAPI.h"

@interface SAShopPreviewVC ()<UITableViewDataSource, UITableViewDelegate, HTTPAPIDelegate, UITextFieldDelegate,YBImageBrowserDataSource>

@property (nonatomic, strong) UIView *topView;
@property (nonatomic, strong) UITextField *searchTf;
@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) UIButton *moreBtn;
@property (nonatomic, strong) UIView *moreView;
@property (nonatomic, strong) UIButton *addBtn;
@property (nonatomic, strong) UIView *addLine;
@property (nonatomic, strong) UIButton *screeningBtn;
@property (nonatomic, strong) UIView *screeningLine;
@property (nonatomic, strong) UIButton *batchBtn;
@property (nonatomic, strong) UIView *batchLine;
@property (nonatomic, assign) NSInteger currentPage;

@property (nonatomic, strong) SAProductListAPI *productListAPI;
@property (nonatomic, strong) NSMutableArray<SAProductOverModel *> *dataMarr;
@property (nonatomic, strong) NSMutableArray *screenArray;
@property (nonatomic, strong) NSString *providerId;
@property (nonatomic, strong) NSString *providerName;
@property (nonatomic, strong) UIButton *topBtn;
@property (nonatomic, strong) UILabel *lineNumLab;
@property (nonatomic, assign) NSInteger lineNum;
@property (nonatomic, strong) UIView *lineborderView;
@property (nonatomic, strong) UIView *tipView;
@property (nonatomic, strong) NSArray *imageList;

@property (nonatomic, strong) UIButton *scanBtn;
@property (nonatomic, strong) NSString *totalRecords;
@property (nonatomic, strong) SAProductGetConditionAPI *productGetConditionAPI;
@property (nonatomic, strong) SAProductBatchIsDeleteAPI *productBatchIsDeleteAPI;

@end

@implementation SAShopPreviewVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

#pragma mark - HTTPAPIDelegate
- (void)fetchData:(id)data fromServerSuccessedWithAPI:(HTTPAPI *)api {
    [self.tableView.mj_header endRefreshing];
    [self.tableView.mj_footer endRefreshing];
    if (self.productListAPI == api) {
        if (self.currentPage == 1) {
            self.lineNum = -1;
            self.dataMarr = [SAProductOverModel mj_objectArrayWithKeyValuesArray:data[@"data"][@"records"]];
            self.totalRecords = data[@"data"][@"totalRecords"];
        }else {
            for (NSDictionary *dict in (NSArray *)data[@"data"][@"records"]) {
                SAProductOverModel *model = [SAProductOverModel mj_objectWithKeyValues:dict];
                [self.dataMarr addObject:model];
            }
        }
        self.lineNumLab.text = [NSString stringWithFormat:@"共%@款,当前%zd款",self.totalRecords,self.dataMarr.count];
        [self.tableView reloadData];
        
        if (self.dataMarr.count > 0) {
            self.topBtn.hidden = NO;
            self.lineNumLab.hidden = NO;
            self.lineborderView.hidden = NO;
            self.tipView.hidden = YES;
        }else{
            self.topBtn.hidden = YES;
            self.lineNumLab.hidden = YES;
            self.lineborderView.hidden = YES;
            self.tipView.hidden = NO;
        }
    }else if (self.productGetConditionAPI == api) {
        NSMutableArray *menuList = [SAValueManger shareInStance].userInfo.menuList;
        NSString *crossStoreProduct = [NSString stringWithFormat:@"%@",menuList[1][@"perms"][@"crossStoreProduct"]];
        [self.screenArray removeAllObjects];
        for ( NSDictionary *dict in (NSArray *)data[@"data"]) {
            SAProductHomeScreeningModel *model = [SAProductHomeScreeningModel mj_objectWithKeyValues:dict];
            if ([model.name isEqualToString:@"店铺"] && [crossStoreProduct isEqualToString:@"0"]) {
                for (SAProductHomeScreeningList *list in model.voList) {
                    if (list.attrId == [SAValueManger shareInStance].userInfo.merchantId) {
                        list.check = YES;
                    }
                }
                [self.screenArray addObject:model];
            }else if ([model.name isEqualToString:@"类别"]) {
                if (model.voList.count > 0) {
                    model.voList[0].check = YES;
                }
                [self.screenArray addObject:model];
            }else if ([model.name isEqualToString:@"性别"]) {
                if (model.voList.count > 0) {
                    model.voList[0].check = YES;
                }
                [self.screenArray addObject:model];
            }else if ([model.name isEqualToString:@"排序"]) {
                NSMutableArray <SAProductHomeScreeningList *>*newList = [NSMutableArray array];
                for (SAProductHomeScreeningList *oldList in model.voList) {
                    if ([oldList.attrName isEqualToString:@"爆款"] || [oldList.attrName isEqualToString:@"滞销款"]) {
                        
                    }else {
                        [newList addObject:oldList];
                    }
                }
                if (newList.count > 0) {
                    newList[0].check = YES;
                }
                model.voList = newList;
                [self.screenArray addObject:model];
            }else if ([model.name isEqualToString:@"状态"]) {
                if (model.voList.count > 1) {
                    model.voList[1].check = YES;
                }
                [self.screenArray addObject:model];
            }else if ([model.name isEqualToString:@"季节"]) {
                if (model.voList.count > 0) {
                    model.voList[0].check = YES;
                }
                [self.screenArray addObject:model];
            }else if ([model.name isEqualToString:@"品牌"]) {
                if (model.voList.count > 0) {
                    model.voList[0].check = YES;
                }
                [self.screenArray addObject:model];
            }else if ([model.name isEqualToString:@"单位"]) {
                if (model.voList.count > 0) {
                    model.voList[0].check = YES;
                }
                [self.screenArray addObject:model];
            }
        }
    }else if (self.productBatchIsDeleteAPI == api) {
        [Prompt popPromptViewWithMsg:@"删除成功" duration:2];
        self.currentPage = 1;
        [self loadData];
    }
}

- (void)fetchDataFromServerFailedWithError:(NSError *)error API:(HTTPAPI *)api {
    [self.tableView.mj_header endRefreshing];
    [self.tableView.mj_footer endRefreshing];
}

#pragma mark - UITableView Delegate & DataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataMarr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    SAShopPreviewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SAShopPreviewCell" forIndexPath:indexPath];
    cell.model = self.dataMarr[indexPath.row];
    WeakSelf
    cell.showImageBlock = ^{
        [weakSelf showImage:weakSelf.dataMarr[indexPath.row].imgList];
    };
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSMutableArray *menuList = [SAValueManger shareInStance].userInfo.menuList;
    NSString *productModifyProduct = [NSString stringWithFormat:@"%@",menuList[1][@"perms"][@"productModifyProduct"]];
    if ([productModifyProduct isEqualToString:@"1"]) {
        [Prompt popPromptViewWithMsg:@"您没有修改商品权限,请联系店长添加" duration:2];
        return;;
    }
    self.moreView.hidden = YES;
    [tableView reloadData];
    __weak typeof(self) weakSelf = self;
    SAEditShopVC *pushVC = [SAEditShopVC new];
    pushVC.productOverModel = self.dataMarr[indexPath.row];
    [self.navigationController pushViewController:pushVC animated:YES];
    pushVC.refreshBlock = ^{
        weakSelf.currentPage = 1;
        [weakSelf loadData];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"updateProduct" object:nil];
    };
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return kScaleNum(71);
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [[UIView alloc] initWithFrame:CGRectZero];
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [[UIView alloc] initWithFrame:CGRectZero];
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return kScaleNum(0.01);
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return SafeFooterHeight;
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    NSMutableArray *menuList = [SAValueManger shareInStance].userInfo.menuList;
    NSString *productViewDelete = [NSString stringWithFormat:@"%@",menuList[1][@"perms"][@"productViewDelete"]];
    if ([productViewDelete isEqualToString:@"1"]) {
        return NO;
    }
    return YES;
}

-(NSArray<UITableViewRowAction*>*)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
    SAProductOverModel *model = self.dataMarr[indexPath.row];
    UITableViewRowAction *rowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault
                                                                         title:@"删除" handler:^(UITableViewRowAction * _Nonnull    action, NSIndexPath * _Nonnull indexPath) {
        [self clickedRemove:model.productId AndStock:model.stock];
    }];
    rowAction.backgroundColor = kPinkColor;
    NSArray *arr = @[rowAction];
    return arr;
}

#pragma mark - UITextField
- (void)textFieldEditChanged:(UITextField *)textField {
    self.productListAPI.productName = textField.text;
    self.currentPage = 1;
    [self loadData];
}

#pragma mark - event
-(void)clickedMoreBtn {
    if (self.moreView.isHidden == YES) {
        self.moreView.hidden = NO;
    }else {
        self.moreView.hidden = YES;
    }
}

-(void)clickedRemove:(NSInteger)productId AndStock:(NSString *)stock{
    NSInteger num = [stock integerValue];
    NSString *msg = @"";
    if (num == 0) {
        msg = @"确认删除商品吗?";
    }else {
        msg = @"选择的商品有库存,确认删除吗?";
    }
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:msg preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *_Nonnull action) {
        NSMutableArray *marr = [NSMutableArray array];
        [marr addObject:@(productId).stringValue];
        self.productBatchIsDeleteAPI.coverParameters = @{@"ids" : marr};
        [self.productBatchIsDeleteAPI sendRequestToServerWithActivityViewAndMask:POST];
    }];
    UIAlertAction *cancelAction =[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    [alert addAction:okAction];
    [alert addAction:cancelAction];
    [self presentViewController:alert animated:true completion:nil];
}

-(void)clickedAddBtn {
    NSMutableArray *menuList = [SAValueManger shareInStance].userInfo.menuList;
    NSString *productNewProducts = [NSString stringWithFormat:@"%@",menuList[1][@"perms"][@"productNewProducts"]];
    if ([productNewProducts isEqualToString:@"1"]) {
        [Prompt popPromptViewWithMsg:@"您没有新增商品权限,请联系店长添加" duration:2];
        return;;
    }
    
    __weak typeof(self) weakSelf = self;
    SAAddShopVC *pushVC = [SAAddShopVC new];
    [self.navigationController pushViewController:pushVC animated:YES];
    self.moreView.hidden = YES;
    pushVC.refreshBlock = ^{
        weakSelf.currentPage = 1;
        [weakSelf loadData];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"updateProduct" object:nil];
    };
}

-(void)clickedScreeningBtn {
    self.moreView.hidden = YES;
    [self prefersStatusBarHidden];
    __weak typeof(self) weakSelf = self;
    SASupplierScreeningView3 *screenView = [SASupplierScreeningView3 shareCornView];
    screenView.delegate = self;
    [screenView loadData:self.screenArray SupplierName:self.providerName SupplierId:self.providerId];
    screenView.screeningBlock = ^(NSMutableArray *selectedArray, NSString *supplierName, NSString *supplierId) {
        [weakSelf.screenArray removeAllObjects];
        [weakSelf.screenArray addObjectsFromArray:selectedArray];
        if (supplierName.length > 0) {
            weakSelf.providerId = supplierId;
            weakSelf.providerName = supplierName;
        }else {
            weakSelf.providerId = @"";
            weakSelf.providerName = @"";
        }
        weakSelf.currentPage = 1;
        [weakSelf loadData];
    };
    [screenView showView:self];
}


-(void)clickedBatchBtn {
    self.moreView.hidden = YES;
    if (self.dataMarr.count == 0) {
        [Prompt popPromptViewWithMsg:@"没有可以处理的数据!" duration:2];
        return;
    }
    SAShopBatchVC *pushVC = [[SAShopBatchVC alloc] initWithProductListAPI:self.productListAPI];
    [self.navigationController pushViewController:pushVC animated:YES];
    WeakSelf
    pushVC.refreshBlock = ^{
        weakSelf.currentPage = 1;
        [weakSelf loadData];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"updateProduct" object:nil];
    };
}

-(void)clickedTopBtn {
    if (self.dataMarr.count > 0) {
        [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
        [self.tableView reloadData];
    }
}

-(void)showImage:(NSArray *)imageList {
    self.imageList = imageList;
    if (self.imageList.count > 0) {
        NSMutableArray *imageMarr = [NSMutableArray array];
        for (NSString *url in self.imageList) {
            NSString *newUrl = [url stringByReplacingOccurrencesOfString:@"?x-oss-process=style/thumbnail" withString:@""];
            NSString *imageUrl = [NSString stringWithFormat:@"%@?x-oss-process=image/resize,l_720",newUrl];
            [imageMarr addObject:imageUrl];
        }
        self.imageList = imageMarr;
        YBImageBrowser *browser = [YBImageBrowser new];
        browser.dataSourceArray = self.imageList;
        browser.dataSource = self;
        browser.currentPage = 0;
        [browser show];
    }else {
        [Prompt popPromptViewWithMsg:@"该商品没有图片" duration:2];
    }
}

-(void)removeView {
    self.moreView.hidden = YES;
}

-(void)clickedScanBtn {
    
    [self.navigationController pushViewController:[[ScanHelper shareInstance] ScanVCWithStyle:notSquare qrResultCallBack:^(id result) {
        //扫码结果
        self.searchTf.text = result;
        self.currentPage = 1;
        [self loadData];
        [self.navigationController popViewControllerAnimated:NO];
    }] animated:YES];
}

//YBImageBrowserDataSource 代理实现赋值数据
- (NSInteger)yb_numberOfCellsInImageBrowser:(YBImageBrowser *)imageBrowser {
    return self.imageList.count;
}

- (id<YBIBDataProtocol>)yb_imageBrowser:(YBImageBrowser *)imageBrowser dataForCellAtIndex:(NSInteger)index {
    NSString *urlStr = [self.imageList objectAtIndex:index];
    YBIBImageData *data = [YBIBImageData new];
    data.imageURL = [NSURL URLWithString:urlStr];
    return data;
}
 
#pragma mark - initUI
-(void)initUI {
    [self setNavigationItemBackBBI:@"" AndTitle:@""];
    [self setBgImage:nil];
    [self addRightViews:@[self.topView]];
    [self.topView addSubview:self.searchTf];
    [self.topView addSubview:self.moreBtn];
    [self.topView addSubview:self.scanBtn];
    [self.view addSubview:self.tableView];
    [self.view addSubview:self.tipView];
    
    [self.view addSubview:self.moreView];
    
    [self.view addSubview:self.topBtn];
    [self.view addSubview:self.lineNumLab];
    
    self.currentPage = 1;
    self.providerId = @"";
    self.providerName = @"";
    [self loadData];
    
    __weak typeof(self) weakSelf = self;
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [weakSelf.view endEditing:YES];
        weakSelf.currentPage = 1;
        [weakSelf loadData];
    }];
    MJRefreshAutoStateFooter *mj_footer = [MJRefreshAutoStateFooter footerWithRefreshingBlock:^{
        [weakSelf.view endEditing:YES];
        weakSelf.currentPage ++;
        [weakSelf loadData];
    }];
    [mj_footer setTitle:@"已经到底啦~" forState:MJRefreshStateIdle];//设置闲置状态下不显示“点击或上拉加载更多”
    self.tableView.mj_footer = mj_footer;
    
    [self.view addSubview:self.topBtn];
    [self.view addSubview:self.lineNumLab];
    [self.view addSubview:self.lineborderView];
    
    [self.lineNumLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(kScaleNum(-SafeFooterHeight-15));
        make.right.mas_equalTo(kScaleNum(-15));
    }];
    [self.lineborderView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lineNumLab.mas_top).offset(kScaleNum(-5));
        make.left.equalTo(self.lineNumLab.mas_left).offset(kScaleNum(-5));
        make.right.equalTo(self.lineNumLab.mas_right).offset(kScaleNum(5));
        make.bottom.equalTo(self.lineNumLab.mas_bottom).offset(kScaleNum(5));
    }];
    [self.topBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(kScaleNum(48));
        make.height.mas_equalTo(kScaleNum(48));
        make.centerX.equalTo(self.lineNumLab.mas_centerX);
        make.bottom.equalTo(self.lineNumLab.mas_top).offset(kScaleNum(-5));
    }];
    
    [self.productGetConditionAPI sendRequestToServerWithActivityViewAndMask:GET];
}

-(void)loadData {
    self.productListAPI.pageSize = 20;
    self.productListAPI.currentPage = self.currentPage;
    self.productListAPI.productName = @"";
    self.productListAPI.providerId = @"";
    
    if (self.searchTf.text.length > 0) {
        self.productListAPI.productName = self.searchTf.text;
    }
    if (self.providerId.length > 0) {
        self.productListAPI.providerId = self.providerId;
    }
    
    self.productListAPI.unitId = @"";
    self.productListAPI.order = @"";
    self.productListAPI.state = @"1";
    self.productListAPI.attrIds = @"";
    self.productListAPI.merchantId = @([SAValueManger shareInStance].userInfo.merchantId).stringValue;
    
    if (self.screenArray.count >0) {
        NSMutableArray *colorArray = [[NSMutableArray alloc] init];
        for (SAProductHomeScreeningModel *model in self.screenArray) {
            if ([model.name isEqualToString:@"店铺"]) {
                for (SAProductHomeScreeningList *list in model.voList) {
                    if (list.check == YES) {
                        self.productListAPI.merchantId = [NSString stringWithFormat:@"%ld",list.attrId];
                    }
                }
            }else if ([model.name isEqualToString:@"单位"]) {
                for (SAProductHomeScreeningList *list in model.voList) {
                    if (list.check == YES &&![list.attrName isEqualToString:@"全部"]) {
                        self.productListAPI.unitId = [NSString stringWithFormat:@"%ld",list.attrId];
                    }
                }
            }else if ([model.name isEqualToString:@"排序"]) {
                for (SAProductHomeScreeningList *list in model.voList) {
                    if (list.check == YES&&![list.attrName isEqualToString:@"默认"]) {
                        self.productListAPI.order = [NSString stringWithFormat:@"%ld",list.attrId];
                    }
                }
            }else if ([model.name isEqualToString:@"状态"]) {
                for (SAProductHomeScreeningList *list in model.voList) {
                    if (list.check == YES) {
                        if ([list.attrName isEqualToString:@"全部"]) {
                            self.productListAPI.state = @"";
                        }else {
                            self.productListAPI.state = [NSString stringWithFormat:@"%ld",list.attrId];
                        }
                    }
                }
            }else
            {
                for (SAProductHomeScreeningList *list in model.voList) {
                    if (list.check == YES&&![list.attrName isEqualToString:@"全部"]) {
                        [colorArray addObject:[NSString stringWithFormat:@"%ld",list.attrId]];
                    }
                }
                if (colorArray.count >0) {
                    self.productListAPI.attrIds = [colorArray componentsJoinedByString:@","];
                }
            }
        }
    }

    [self.productListAPI sendRequestToServerWithActivityViewAndMask:POST];
}

#pragma mark - lazy
-(UIView *)topView {
    if (!_topView) {
        _topView = [[UIView alloc] initWithFrame:SARectMake(50, 0, 325, 44)];
    }
    return _topView;
}

-(UIButton *)scanBtn {
    if (!_scanBtn) {
        _scanBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _scanBtn.frame = SARectMake(0, 0, 30, 44);
        [_scanBtn setImage:[UIImage imageNamed:@"home_scan"] forState:UIControlStateNormal];
        [_scanBtn addTarget:self action:@selector(clickedScanBtn) forControlEvents:UIControlEventTouchUpInside];
    }
    return _scanBtn;
}

-(UITextField *)searchTf {
    if (!_searchTf) {
        _searchTf = [[UITextField alloc] initWithFrame:SARectMake(45, 7, 220, 30)];
        _searchTf.placeholder = @"输入商品款号/名称/条码";
        _searchTf.backgroundColor = [UIColor whiteColor];
        _searchTf.layer.cornerRadius = kScaleNum(5);
        _searchTf.layer.masksToBounds = YES;
        _searchTf.delegate = self;
        _searchTf.font = kFont(14);
        _searchTf.clearButtonMode = UITextFieldViewModeWhileEditing;
        UIView *leftView = [[UIView alloc] initWithFrame:SARectMake(0, 0, 26, 30)];
        UIImageView *imageV = [[UIImageView alloc] initWithFrame:SARectMake(6, 7, 14, 16)];
        imageV.image = [UIImage imageNamed:@"shop_search"];
        [leftView addSubview:imageV];
        _searchTf.leftView = leftView;
        _searchTf.leftViewMode = UITextFieldViewModeAlways;
        [_searchTf addTarget:self action:@selector(textFieldEditChanged:) forControlEvents:UIControlEventEditingChanged];
    }
    return _searchTf;
}

-(UIButton *)moreBtn {
    if (!_moreBtn) {
        _moreBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_moreBtn setImage:[UIImage imageNamed:@"shop_more"] forState:UIControlStateNormal];
        _moreBtn.frame = SARectMake(270, 0, 55, 44);
        [_moreBtn addTarget:self action:@selector(clickedMoreBtn) forControlEvents:UIControlEventTouchUpInside];
    }
    return _moreBtn;
}

-(UIView *)moreView {
    if (!_moreView) {
        _moreView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
        _moreView.backgroundColor = kColor(0, 0, 0, 0.3);
        _moreView.hidden = YES;
        _moreView.userInteractionEnabled = YES;
        
        UIImageView *imageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"shop_moreView"]];
        imageV.frame = SARectMake(272, StatusHeight - 6, 95, 116);
        [_moreView addSubview:imageV];
        imageV.userInteractionEnabled = YES;
        
        [imageV addSubview:self.addBtn];
        [imageV addSubview:self.addLine];
        [imageV addSubview:self.screeningBtn];
        [imageV addSubview:self.screeningLine];
        [imageV addSubview:self.batchBtn];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(removeView)];
        [_moreView addGestureRecognizer:tap];
    }
    return _moreView;
}

-(UIButton *)addBtn {
    if (!_addBtn) {
        _addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_addBtn setImage:[UIImage imageNamed:@"shop_add"] forState:UIControlStateNormal];
        _addBtn.frame = SARectMake(0, 10, 95, 34);
        [_addBtn setTitle:@"  新增商品" forState:UIControlStateNormal];
        _addBtn.titleLabel.font = kFont(14);
        [_addBtn setTitleColor:kBlackColor forState:UIControlStateNormal];
        [_addBtn addTarget:self action:@selector(clickedAddBtn) forControlEvents:UIControlEventTouchUpInside];
    }
    return _addBtn;
}

-(UIView *)addLine {
    if (!_addLine) {
        _addLine = [[UIView alloc] initWithFrame:SARectMake(10, 44, 75, 1)];
        _addLine.backgroundColor = kLineColor;
    }
    return _addLine;
}

-(UIButton *)screeningBtn {
    if (!_screeningBtn) {
        _screeningBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_screeningBtn setImage:[UIImage imageNamed:@"shop_screening"] forState:UIControlStateNormal];
        _screeningBtn.frame = SARectMake(0, 45, 95, 34);
        [_screeningBtn setTitle:@"  筛选商品" forState:UIControlStateNormal];
        _screeningBtn.titleLabel.font = kFont(14);
        [_screeningBtn setTitleColor:kBlackColor forState:UIControlStateNormal];
        [_screeningBtn addTarget:self action:@selector(clickedScreeningBtn) forControlEvents:UIControlEventTouchUpInside];
    }
    return _screeningBtn;
}

-(UIView *)screeningLine {
    if (!_screeningLine) {
        _screeningLine = [[UIView alloc] initWithFrame:SARectMake(10, 79, 75, 1)];
        _screeningLine.backgroundColor = kLineColor;
    }
    return _screeningLine;
}

-(UIButton *)batchBtn {
    if (!_batchBtn) {
        _batchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_batchBtn setImage:[UIImage imageNamed:@"shop_batch"] forState:UIControlStateNormal];
        _batchBtn.frame = SARectMake(0, 80, 95, 34);
        [_batchBtn setTitle:@"  批量操作" forState:UIControlStateNormal];
        _batchBtn.titleLabel.font = kFont(14);
        [_batchBtn setTitleColor:kBlackColor forState:UIControlStateNormal];
        [_batchBtn addTarget:self action:@selector(clickedBatchBtn) forControlEvents:UIControlEventTouchUpInside];
    }
    return _batchBtn;
}

-(UIView *)batchLine {
    if (!_batchLine) {
        _batchLine = [[UIView alloc] initWithFrame:SARectMake(10, 104, 75, 1)];
        _batchLine.backgroundColor = kLineColor;
    }
    return _batchLine;
}

-(UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, kScaleNum(StatusHeight), kScreenWidth, kScreenHeight - kScaleNum(StatusHeight)) style:UITableViewStylePlain];
        if (@available(iOS 15.0, *)) {
            _tableView.sectionHeaderTopPadding = 0;
        }
        _tableView.backgroundColor = [UIColor whiteColor];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.showsHorizontalScrollIndicator = NO;
        if (@available(iOS 11.0, *)) {
            _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }
        _tableView.estimatedRowHeight = 0;
        _tableView.estimatedSectionHeaderHeight = 0;
        _tableView.estimatedSectionFooterHeight = 0;
        [_tableView registerClass:[SAShopPreviewCell class] forCellReuseIdentifier:@"SAShopPreviewCell"];
    }
    return _tableView;
}

-(SAProductListAPI *)productListAPI {
    if (!_productListAPI) {
        _productListAPI = [SAProductListAPI apiWithDelegate:self];
    }
    return _productListAPI;
}

-(NSMutableArray<SAProductOverModel *> *)dataMarr {
    if (!_dataMarr) {
        _dataMarr = [NSMutableArray array];
    }
    return _dataMarr;
}

-(NSMutableArray *)screenArray {
    if(!_screenArray) {
        _screenArray = [NSMutableArray array];
    }
    return _screenArray;
}

-(UIButton *)topBtn {
    if (!_topBtn) {
        _topBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_topBtn setImage:[UIImage imageNamed:@"shop_topBtn"] forState:UIControlStateNormal];
        [_topBtn addTarget:self action:@selector(clickedTopBtn) forControlEvents:UIControlEventTouchUpInside];
    }
    return _topBtn;
}

-(UILabel *)lineNumLab {
    if (!_lineNumLab) {
        _lineNumLab = [[UILabel alloc] init];
        _lineNumLab.textColor = kColor(109, 135, 243, 1);
        _lineNumLab.numberOfLines = 0;
        _lineNumLab.textAlignment = NSTextAlignmentCenter;
        _lineNumLab.font = kFont(12);
    }
    return _lineNumLab;
}

-(UIView *)lineborderView {
    if (!_lineborderView) {
        _lineborderView = [[UIView alloc] init];
        _lineborderView.layer.borderColor = kColor(109, 135, 243, 1).CGColor;
        _lineborderView.layer.borderWidth = kScaleNum(1);
        _lineborderView.layer.cornerRadius = kScaleNum(3);
    }
    return _lineborderView;
}

-(UIView *)tipView {
    if (!_tipView) {
        _tipView = [[UIView alloc] initWithFrame:CGRectMake(0, kScaleNum(StatusHeight), kScreenWidth, kScreenHeight - kScaleNum(StatusHeight))];
        _tipView.backgroundColor = [UIColor whiteColor];
        UIImageView *icon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Shop_search2"]];
        icon.frame = SARectMake(124, 147 - StatusHeight, 138, 83);
        [_tipView addSubview:icon];
        UILabel *titleLab = [[UILabel alloc] initWithFrame:SARectMake(0, 240 - StatusHeight, kBaseScreenWidth, 30)];
        titleLab.text = @"暂无相关信息";
        titleLab.textAlignment = NSTextAlignmentCenter;
        titleLab.textColor = kGrayColor;
        [_tipView addSubview:titleLab];
    }
    return _tipView;
}

-(SAProductGetConditionAPI *)productGetConditionAPI {
    if (!_productGetConditionAPI) {
        _productGetConditionAPI = [SAProductGetConditionAPI apiWithDelegate:self];
    }
    return _productGetConditionAPI;
}

-(SAProductBatchIsDeleteAPI *)productBatchIsDeleteAPI {
    if (!_productBatchIsDeleteAPI) {
        _productBatchIsDeleteAPI = [SAProductBatchIsDeleteAPI apiWithDelegate:self];
    }
    return _productBatchIsDeleteAPI;
}


@end
